﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace TST.DemoCode.FeatureReceivers
{
    public class TSTBaseFeatureReceiver : SPFeatureReceiver
    {
        protected SPFeatureReceiverProperties _properties;

        protected String GetSettingFromProperties(string propertyName, bool required)
        {
            if (_properties == null)
            {
                throw new SPException("Properties not found.");
            }
            SPFeatureProperty property = null;
            foreach (SPFeatureProperty search in _properties.Definition.Properties)
                if (String.Compare(search.Name, propertyName, true) == 0)
                    property = search;
            if (property == null)
                throw new SPException(string.Format("Property {0} not found in the Feature Definition", propertyName));
            if (required && string.IsNullOrEmpty(property.Value.Trim()))
                throw new SPException(string.Format("Property {0} must have a value in the Feature Definition", propertyName));
            return property.Value;
        }

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }
    }
}
